package com.hxzy.projectssmplus.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.hxzy.projectssmplus.dto.SysDicDataDTO;
import com.hxzy.projectssmplus.entity.SysDictData;
import com.hxzy.projectssmplus.entity.SysDictType;
import com.hxzy.projectssmplus.service.SysDictDataService;
import com.hxzy.projectssmplus.service.SysDictTypeService;
import com.hxzy.projectssmplus.vo.AjaxResult;
import com.hxzy.projectssmplus.vo.AjaxTableInfo;
import javafx.scene.chart.PieChart;
import lombok.Data;
import org.apache.http.client.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.Date;
import java.util.List;
import java.util.Scanner;

@RestController
public class DataController extends BaseController{
    @Autowired
    private SysDictDataService sysDictDataService;
    @Autowired
    private SysDictTypeService sysDictTypeService;
    @GetMapping(value = "/data/data")
    public AjaxTableInfo adtaData(SysDicDataDTO sysDicDataDTO){
        List<SysDictData> sysDictData = this.sysDictDataService.searchByXML(sysDicDataDTO);
        IPage iPage = super.startPage();
        iPage.setRecords(sysDictData);
       return   super.getTableInfo(iPage);
    }

    @GetMapping(value = "/data/type")
    public AjaxResult dataType(){
        List<SysDictType> sysDictTypes = this.sysDictTypeService.searType();
//        System.out.println("返回的数据条数   "+sysDictTypes.size());
        return AjaxResult.success_data(sysDictTypes);
    }
    @GetMapping(value = "/data/add")
    public AjaxResult dataAdd(SysDictData sysDictData){
        Date date = new Date();
        sysDictData.setCreateTime(date);
        Integer integer = this.sysDictDataService.addData(sysDictData);
        return integer>0?AjaxResult.success("data/add 添加数据成功"):AjaxResult.error("data/add添加数据失败");
    }
    @GetMapping(value = "data/del")
    public AjaxResult dataDel(Long dictCode){
       // System.out.println("data/del 获取的数据  "+dictCode);
        Integer integer = this.sysDictDataService.delData(dictCode);
        return integer>0?AjaxResult.success("data/del 删除数据成功"):AjaxResult.error("data/del删除数据失败");
    }
    @GetMapping(value = "/data/updata")
    public AjaxResult dataUpdata(SysDictData sysDictData){
    //    System.out.println("data/updata接收到的属性  "+sysDictData.getDictCode());
        Integer integer = this.sysDictDataService.upDataData(sysDictData);
        return integer>0?AjaxResult.success("data/updata修改数据成功"):AjaxResult.error("data/updata修改数据失败");
    }


    @GetMapping(value = "/data/types/{type}")
    public AjaxResult getType(@PathVariable(value = "type") String type){
        System.out.println("种类获得的参数   "+type);
        List<SysDictData> sysDictData = this.sysDictDataService.searchByType(type);
        return AjaxResult.success_data(sysDictData);
    }
}
